var UserSettingPage = {
	// 保存所有用户设置信息
	'save': function() {
		var userSettings = [];
		$("#userSettingFrm").find("[data-type='setting-item']").each(function() {
			var $this = $(this);
			var obj = {
				'valueType': $this.find("input[name='valueType']").val(),
				'settingValue': $this.find("input[name='settingValue']").val(),
				'settingKey': $this.find("input[name='settingKey']").val(),
			};
			userSettings.push(obj);
		});
		var data = $.toJSON({
			'userSettings': userSettings
		});
		saveAllUserSettingAjax.setData(data).send();
	},
	// 保存成功回调
	'onSaveAllSucc': function(data, status, xhr) {
		$.messager.info(data.message);
		MsgBox.closeActiveDialog();
	},
	// 打开选择菜单页面
	'openSelectMenusPage': function() {
		// 打开对话框
		MsgBox.open("openSelectMenusPage", "选择菜单", ctx + "/sys/menu/select/2/UserSettingPage/-/index", "600px");
	},
	// 选择了菜单的值后的回调
	'onMenuValuesSelected': function(values) {
		// 设值
		var $container = $("[data-key='automenu']");
		var $val = $container.find("input[name='settingValue']");
		var s = $.arrayToString(values, ',');
		$val.val(s);
		
		// 页面textarea显示
		getTreeShapeResourceNamesAjax.setData({
			'resIdArr': values
		}).send();
	},
	// 查询树状资源名成功回调
	'onGetNameSucc': function(data, status, xhr) {
		var $container = $("[data-key='automenu']");
		var $val = $container.find("textarea#automenu");
		if (data.info == null || data.info.length <= 0) {
			$val.text('');
			return ;
		}
		var s = $.arrayToString(data.info, '\n');
		$val.text(s);
	},
	// 已查询到当前用户当前角色的settingKeys
	'findCurrentRoleSettingKeysSucc': function(data, status, xhr) {
		var gs = new GenericSet(data.info);
		$("#userSettingFrm").find("[data-type='setting-item']").each(function() {
			var key = $(this).data("key");
			if (gs.hasItem(key)) {
				$(this).show();
			} else {	
				$(this).remove();
			}
		});
		findAllSettingsAjax.send();
	},
	'SETTING_MAPPING': {
		'automenu': function(item) {
			$.store.set("autoMenuValues", item.settingValues);
			getTreeShapeResourceNamesAjax.setData({
				'resIdArr': item.settingValues
			}).send();
		}
	},
	// 查询到当前用户所有设置回调
	'findAllSettingsSucc': function(data, status, xhr) {
		var gs = new GenericSet(data.info);
		$("#userSettingFrm").find("[data-type='setting-item']").each(function() {
			var key = $(this).data("key");
			var item = gs.getItemByKey('settingKey', key);
			UserSettingPage.SETTING_MAPPING[key] && UserSettingPage.SETTING_MAPPING[key](item);
		});
	},
	'getInitMenus': function() {
		var menus = $.store.get("autoMenuValues");
		return menus;
	}
};